// -*- mode:C; tab-width:2; indent-tabs-mode:nil;  -*-
// $Id: hashTable.h,v 1.7 2010/04/21 00:21:41 zahorjan Exp $

#ifndef HASHTABLE_H
#define HASHTABLE_H

/************************************************************
 * Hash table implementation.
 * Doesn't have to be thread safe.
 * Doesn't have to be dynamically resized.
 ************************************************************/

#include "factory.h"

EXPOSETYPE(hashTable_t)

typedef int (*hash_fn_t)(void* key);                       // a client-supplied hash function: key -> int
typedef int (*hash_key_cmp_fn_t)(void* keyA, void* keyB);  // returns 0 if the keys are equal, not-zero otherwise
typedef void (*hash_value_destroy_fn_t)(void* value);      // callback to client code to destroy a value, if the hash table
                                                           //   isn't empty when it's destroyed
typedef void (*hash_key_destroy_fn_t)(void* key);          // callback to destroy a key

extern hashTable_t hashTable_create( int                     size,         // table size
                                     hash_fn_t               hashFunc,     // client's hash function
                                     hash_key_cmp_fn_t       keyCmpFunc    // client's key comparison function
                                   );

// well... destroys the hash table
extern int hashTable_destroy( hashTable_t t,
                              hash_key_destroy_fn_t   destroyKeyFunc,
                              hash_value_destroy_fn_t destroyValFunc
                            );


extern int addHashItem(hashTable_t t, void* key, void* value, hash_key_destroy_fn_t destroyKeyFunc, hash_value_destroy_fn_t destroyValFunc);
extern void* lookupHashItem(hashTable_t t, void* key);

extern void hashtable_debug(hashTable_t h);

#endif // HASHTABLE_H
